package com.uchengwang.ui.cm_ui.cycle.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.http.config.BaseConfig;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.cycle.bean.TalentPeopleBean;
import com.uchengwang.ui.cm_ui.cycle.ui.LoadCycleWebHtmlActivity;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2018/6/15.
 */

public class TalentListAdapter extends RecyclerView.Adapter<TalentListAdapter.TalentListVH>{
    private Context context;
    private List<TalentPeopleBean> data = new ArrayList<>();
    public TalentListAdapter (Context context){
        this.context = context;
    }


    public List<TalentPeopleBean> getData() {
        return data;
    }

    public void setData(List<TalentPeopleBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }


    @Override
    public TalentListVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_layout_talent_list, parent, false);
        return new TalentListVH(view);
    }

    @Override
    public void onBindViewHolder(TalentListVH holder, int position) {
        final TalentPeopleBean bean = data.get(position);
        ImageManager.getInstance().loadImage(context,holder.list_head, bean.getUserAvatar(), ImageManager.ImageType.CIRCLE);
        holder.list_name.setText(bean.getNickName());
        holder.list_school.setText(bean.getUniName());
        holder.rankNum.setText(position + 4 + "");

        holder.list_num_tv.setText(bean.getTalentScore() + "");

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LoadCycleWebHtmlActivity.class);
                intent.putExtra(BaseConfig.URL, BaseConfig.BaseWebURL + "/user/"+bean.getUid());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class TalentListVH extends RecyclerView.ViewHolder {
        private View itemView;
        private ImageView list_head, list_num_image;
        private TextView rankNum, list_name, list_school, list_num_tv;

        public TalentListVH(View view) {
            super(view);

            AutoUtils.auto(view);
            itemView = view;
            list_head = view.findViewById(R.id.list_head);
            list_num_image = view.findViewById(R.id.list_num_image);
            rankNum = view.findViewById(R.id.rankNum);
            list_name = view.findViewById(R.id.list_name);
            list_school = view.findViewById(R.id.list_school);
            list_num_tv = view.findViewById(R.id.list_num_tv);

        }
    }
}
